package cn.tedu.boyou.mgrsite.controller;

import cn.tedu.boyou.acticle.domain.DestTheme;
import cn.tedu.boyou.acticle.domain.Destination;
import cn.tedu.boyou.acticle.domain.DestinationExtend;
import cn.tedu.boyou.acticle.domain.Festival;
import cn.tedu.boyou.acticle.service.IDestExtendService;
import cn.tedu.boyou.acticle.service.IDestThemeService;
import cn.tedu.boyou.acticle.service.IDestinationService;
import cn.tedu.boyou.acticle.service.IFestivalService;
import cn.tedu.boyou.common.query.DestinationExtendQuery;
import cn.tedu.boyou.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 目的地
 */
@Controller
@RequestMapping("/destinationTags")
public class DestinationTagsController {

    @Reference
    private IDestExtendService destExtendService;
    @Reference
    private IDestThemeService themeService;
    @Reference
    private IFestivalService festivalService;
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")DestinationExtendQuery qo){
        //toasts
        List<Destination> toasts = destinationService.getToasts(qo.getDestParentId());
        model.addAttribute("toasts",toasts);
        //pageInfo<DestinationExtend>
        PageInfo<DestinationExtend> pageInfo = destExtendService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "destinationTags/list";
    }

    @RequestMapping("/update")
    @ResponseBody
    public AjaxResult saveOrUpdate(DestinationExtend destinationExtend){
        destExtendService.update(destinationExtend);
        return new AjaxResult();
    }

    @RequestMapping("/listThemes")
    @ResponseBody
    public Object listThemes(int deep){
        List<DestTheme> list = themeService.listThemesByDeep(deep);
        AjaxResult data = new AjaxResult().addData(list);
        return data;
    }

    @RequestMapping("/listFestivals")
    @ResponseBody
    public Object listFestivals(){
        List<Festival> list = festivalService.list();
        AjaxResult data = new AjaxResult().addData(list);
        return data;
    }
}
